// 请求统一的出口
import ZHRequest from './request'
import {
    BASE_URL
} from './request/config'
import {
    getToken
} from '@/utils/auth.js'
// 返回的第一个请求函数
const Request = new ZHRequest({
    baseURL: BASE_URL,
    timeout: 15000,
    interceptors: {
        requestInterceptor: (config) => {
            const token = getToken()
            if (token) {
                config.headers.Authorization = `Bearer ${token}`
            }
            // console.log('独立类请求拦截')
            return config
        },
        requestInterceptorCatch: (err) => {
            console.log(err)
            return err
        },
        responseInterceptor: (res) => {
            // console.log('独立类响应拦截')
            return res
        },
        responseInterceptorCatch: (err) => {
            return err
        }
    }
})

export default Request